#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

/**
 * PAT A 1105 Spiral Matrix
 */

int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int rows, cols;
int **matrix;

inline bool canFill(int r, int c) {
    return r >= 0 && r < rows && c >= 0 && c < cols && matrix[r][c] == -1;
}

int main() {
    // Read numbers and sort
    int num;
    scanf("%d", &num);
    std::vector<int> values(num);
    for (int i = 0; i < num; i++) scanf("%d", &values[i]);
    std::sort(values.begin(), values.end(), std::greater<int>());

    // Compute rows and columns of matrix
    cols = sqrtf(num);
    while (num % cols != 0) cols--;
    rows = num / cols;

    // Fill in matrix
    matrix = new int *[rows];
    for (int i = 0; i < rows; i++) {
        matrix[i] = new int[cols];
        for (int j = 0; j < cols; j++) matrix[i][j] = -1;
    }
    int r = 0, c = 0, total = 0;
    int d = 0;
    while (total < num) {
        matrix[r][c] = values[total];
        total++;
        int nr = r + dir[d][0], nc = c + dir[d][1];
        if (!canFill(nr, nc)) {
            d = (d + 1) % 4;
            nr = r + dir[d][0];
            nc = c + dir[d][1];
        }
        r = nr;
        c = nc;
    }

    // Print matrix
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            if (j != 0) printf(" ");
            printf("%d", matrix[i][j]);
        }
        printf("\n");
    }

    return 0;
}